<?php
	class ModelComplateComplate extends Model {
		public function addComplate($data,$kid,$user_id) {
			for ($i=0; $i < 8; $i++) { 
				$query=$this->db->query("INSERT INTO complate SET kid = '" . (int)$kid . "', user_id = '" . (int)$user_id ."', times = '" . ($i+1) . "', date = '" .$this->db->escape($data[$i]) ."'");
				$result += $query; 
			}
			return $result;
		}
		public function updateComplate($data,$kid,$user_id){
			for ($i=0; $i < 8; $i++) { 
				$query=$this->db->query("UPDATE complate SET  date = '" .$this->db->escape($data[$i]) ."' , star = 0 WHERE kid = '" . (int)$kid . "' AND user_id = '" . (int)$user_id ."' AND times = '" . ($i+1) . "'");
				$result += $query; 
			}
			return $result;
		}
		public function getComplateByKid($kid){
			$query = $this->db->query("SELECT * FROM complate WHERE kid = '".(int)$kid."'");
			return $query->rows;
		}
		public function cleanComplate(){
			$query = $this->db->query("TRUNCATE TABLE complate");
			return $query->row;
		}
		public function deleteComplate($kid){
			$this->db->query("DELETE FROM complate WHERE kid='".(int)$kid."'");
			return true;
		}
		public function selectStar($data) {
			$this->db->query("UPDATE complate SET star ='" . $this->db->escape($data['star']) ."' WHERE id = '" . $this->db->escape($data['cid']) . "'");
			return $this->db->countAffected();
		}
	}